class PersonUI extends egret.Sprite {

    public constructor() {
        super();
        this.createView();
    }

    private textField: egret.TextField;

    private createView(): void {
        //水花背景   
        var personBG = createBitmap("swin_bg_png")
        this.addChild(personBG);
        var personBG2 = createBitmap("swin_shuihua_png", 0, 0);
        this.addChild(personBG2);
        //logo
        var person_logo = createBitmap("jianqiezu_02_png", 416, 38);
        this.addChild(person_logo);
        var person_jiaru = createTextFiled("加入安联会员大家庭", 100, 210, 50, 0xffffff)
        person_jiaru.multiline = true;
        person_jiaru.bold = true;
        this.addChild(person_jiaru);
        var person_jiaru1 = createTextFiled("即刻抽奖", 100, 268, 50, 0xffffff)
        person_jiaru.multiline = true;
        person_jiaru.bold = true;
        this.addChild(person_jiaru1);
        var person_tell = createTextFiled("请输入您的手机号", 100, 410, 30, 0xffffff)
        person_tell.multiline = true;
        person_tell.bold = true;
        this.addChild(person_tell);
        //输入手机号码
        var person_middle = new egret.DisplayObjectContainer();
        var shape = new egret.Shape();
        shape.graphics.beginFill(0xffffff)
        shape.graphics.lineTo(100, 455);
        shape.graphics.lineTo(550, 455);
        shape.graphics.lineTo(550, 520);
        shape.graphics.lineTo(100, 520);
        shape.graphics.lineTo(100, 455);
        shape.graphics.endFill();
        person_middle.addChild(shape);
        this.addChild(person_middle);
        //输入框
        var middle_input = createTextFiled("")
        middle_input.type = egret.TextFieldType.INPUT;
        middle_input.textAlign = "left"
        middle_input.width = 400;
        middle_input.height = 50;
        middle_input.textColor = 0x000000;
        person_middle.addChild(middle_input);
        middle_input.x = 120;
        middle_input.y = 460;
        middle_input.maxChars = 11
        //短信验证码
        var duanxin = createTextFiled("短信验证码", 100, 660, 30, 0xffffff)
        duanxin.multiline = true;
        duanxin.bold = true;
        this.addChild(duanxin);
        //短信
        var person_middle2 = new egret.DisplayObjectContainer();
        var shape = new egret.Shape();
        shape.graphics.beginFill(0xffffff)
        shape.graphics.lineTo(100, 715);
        shape.graphics.lineTo(410, 715);
        shape.graphics.lineTo(410, 785);
        shape.graphics.lineTo(100, 785);
        shape.graphics.lineTo(100, 715);
        shape.graphics.endFill();
        person_middle2.addChild(shape);
        this.addChild(person_middle2);
        //输入框
        var middle_input2 = createTextFiled("")
        middle_input2.type = egret.TextFieldType.INPUT;
        middle_input2.textAlign = "left"
        middle_input2.width = 250;
        middle_input2.height = 50;
        middle_input2.textColor = 0x000000;
        person_middle2.addChild(middle_input2);
        middle_input2.x = 120;
        middle_input2.y = 726;
        middle_input2.maxChars = 6
        //点击验证
        var panduan = createTextFiled("", 100, 520, 25)
        panduan.multiline = true;
        panduan.bold = true;
        //判断手机号码
        var mobile;
        middle_input.addEventListener(egret.FocusEvent.FOCUS_OUT, function () {
            mobile = parseInt(middle_input.text);
            var reg = /(^13\d{9}$)|(^14)[5,7]\d{8}$|(^15[0,1,2,3,5,6,7,8,9]\d{8}$)|(^17)[6,7,8]\d{8}$|(^18\d{9}$)/g;
            if (reg.test(mobile)) {
                panduan.text = "手机号码正确 √ "
                panduan.textColor = 0x10fb42;
                yanzhen_btn.touchEnabled = true
            } else {
                panduan.text = "手机号码错误 "
                panduan.textColor = 0xea0722;
            }
            this.addChild(panduan);
        }, this)
        //倒计时
        var input_border4 = new egret.DisplayObjectContainer();
        var roundRect = new egret.Shape();
        roundRect.graphics.beginFill(0xfff530)
        roundRect.graphics.lineStyle(2, 0xa0a0a0);
        roundRect.graphics.drawRoundRect(400, 555, 120, 66, 30, 30);
        roundRect.graphics.endFill();
        input_border4.addChild(roundRect);
        this.addChild(input_border4);
        //验证码

        var yanzhen_btn = createBitmap("yanzhen_btn_png", 100, 550)
        this.addChild(yanzhen_btn);
        var yanzhen1 = createTextFiled("获取验", 420, 560, 25, 0xfe3c63)
        yanzhen1.bold = true
        input_border4.addChild(yanzhen1);
        var yanzhen2 = createTextFiled("证码 ", 435, 590, 25, 0xfe3c63)
        input_border4.addChild(yanzhen2);
        yanzhen_btn.addEventListener(egret.TouchEvent.TOUCH_TAP, function (
        ) {
            egret.Tween.get(yanzhen_btn).to({ y: 555 }, 300).to({ y: 550 }, 200);
            var time2 = 60
            var time1 = setInterval(function () {
                yanzhen1.text = "倒计时";
                input_border4.addChild(yanzhen1);
                time2 -= 1
                yanzhen2.text = time2 + "S"
                input_border4.addChild(yanzhen2);

                //   alert(111111)
                if (time2 < 1) {
                    var roundRect = new egret.Shape();
                    roundRect.graphics.beginFill(0xfff530)
                    roundRect.graphics.lineStyle(2, 0xa0a0a0);
                    roundRect.graphics.drawRoundRect(400, 555, 120, 66, 30, 30);
                    roundRect.graphics.endFill();
                    input_border4.addChild(roundRect);
                    yanzhen1.text = "重新获";
                    input_border4.addChild(yanzhen1);
                    yanzhen2.text = "取"
                    input_border4.addChild(yanzhen2);
                    yanzhen_btn.touchEnabled = true
                    time2 = 60;
                    clearInterval(time1);
                }
            }, 1000)
            MYajax({ "phone": middle_input.text }, "http://swin.bluej.cn/index.php/Home/app/verification_code.html", function (res) {
                console.log(res);
            });
            var roundRect = new egret.Shape();
            roundRect.graphics.beginFill(0xffffff)
            roundRect.graphics.lineStyle(2, 0xa0a0a0);
            roundRect.graphics.drawRoundRect(400, 555, 120, 66, 30, 30);
            roundRect.graphics.endFill();
            input_border4.addChild(roundRect);
        }, this)


        var person_btn = createBitmap("jianqiezu_04_png", 100, 900)
        this.addChild(person_btn);
        var yz_text = createTextFiled("验证码有误", 440, 727, 35, 0xff0000);
        this.addChild(yz_text);
        yz_text.alpha = 0;
        person_btn.touchEnabled = true
        person_btn.addEventListener(egret.TouchEvent.TOUCH_TAP, function (
        ) {
            egret.Tween.get(person_btn).to({ y: 910 }, 300).to({ y: 900 }, 200);
            MYajax({ "phone": middle_input.text, "code": middle_input2.text }, "http://swin.bluej.cn/index.php/Home/app/verification_phone.html", function (res) {
                res.state = 1;//强制设置可以点击‘前往领奖台’
                console.log(res)
                if (res.state == 1) {
                    person_btn.touchEnabled = false;//如果验证码正确，可以进入此处，点击后不再可点击，防止多次点击
                    var senceManage = SenceManage.create();
                    SenceManage.create(this.stage).loadSence("preload", null, choujiangUI);
                    egret.Tween.get(this).to({ x: -640 }, 500);

                } else {
                    yz_text.alpha = 1;
                }
            }.bind(this));
        }, this)
    }

    public setProgress(current: number, total: number): void {
        this.textField.text = `Loading...${current}/${total}`;
    }
}
